﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SMTC.Model.Model;
using SMTC.BO.BaseInfo;
using SMTC.WebCommon.Common;
using SMTC.BO.DataServer;

public partial class PlanMangement_PlanView : BasePage
{
    ProductBaseInfoServices _services = new ProductBaseInfoServices();
    DataServerServices _dataService = new DataServerServices();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btn_Save_Click(object sender, EventArgs e)
    {
        SMT_ProductBaseInfoModel model = new SMT_ProductBaseInfoModel();

        if (string.IsNullOrEmpty(hid_ID.Value.Trim()))
        {
            model.ID = Guid.NewGuid().ToString();
        }
        else
        {
            model.ID = hid_ID.Value.Trim();
        }
        model.ProductCode = txtM_ProductCode.Text.Trim();
        model.UnitCount = ConvertDateType.IntParse(txtM_UnitCount.Text.Trim());
        model.Para = ConvertDateType.FloatTryFormat(txtM_Para.Text.Trim());
        model.Operation = this.UserName;
        model.OperationTime = DateTime.Now;
        if (cbx_isTemp.Checked == true)
        {
            model.isTemp = 1;
        }
        else
        {
            model.isTemp = 0;
        }

        if (_services.InsertOrUpdate(model) == true)
        {
            this.ShowMessage(Resources.Resource.InsertSuccess);//"插入成功！"
        }
        else
        {
            this.ShowMessage(Resources.Resource.InsertFailed);//"插入失败！"
        }
        gvProductView.DataBind();
    }

    protected void gvProductView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Del")
        {
            if (_services.DeleteProduct(e.CommandArgument.ToString()) == true)
            {
                this.ShowMessage(Resources.Resource.DeleteSuccess);//"删除成功！"
            }
            else
            {
                this.ShowMessage(Resources.Resource.DeleteFailed);//"删除失败！"
            }
            gvProductView.DataBind();
        }
    }

    protected void btn_Query_Click(object sender, EventArgs e)
    {
        gvProductView.DataBind();
    }

    protected void btn_Upload_Click(object sender, EventArgs e)
    {
        Server.Transfer("UpLoadMateril.aspx");
    }
    protected void btn_UnitMount_Click(object sender, EventArgs e)
    {
        int count = _dataService.GetUnitCount();
        if (count >= 0)
        {
            ShowMessage("Success! count:" + count);
        }
        else
        {
            ShowMessage("Fail");
        }
    }
}